package wechat.base.snd;

import java.util.Collection;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.json.JSONArray;
import org.json.JSONObject;
import wechat.base.snd.WCButton;

@SuppressWarnings("all")
public class WCMenu {
  private Collection<WCButton> buttons = CollectionLiterals.<WCButton>newArrayList();
  
  public void withButton(final WCButton b) {
    this.buttons.add(b);
  }
  
  public JSONObject build() {
    JSONObject _jSONObject = new JSONObject();
    final Procedure1<JSONObject> _function = new Procedure1<JSONObject>() {
      public void apply(final JSONObject it) {
        try {
          JSONArray _jSONArray = new JSONArray();
          final Procedure1<JSONArray> _function = new Procedure1<JSONArray>() {
            public void apply(final JSONArray it) {
              for (final WCButton b : WCMenu.this.buttons) {
                it.put(b.toJson());
              }
            }
          };
          JSONArray _doubleArrow = ObjectExtensions.<JSONArray>operator_doubleArrow(_jSONArray, _function);
          it.put("button", _doubleArrow);
        } catch (Throwable _e) {
          throw Exceptions.sneakyThrow(_e);
        }
      }
    };
    return ObjectExtensions.<JSONObject>operator_doubleArrow(_jSONObject, _function);
  }
  
  public WCButton createBtn() {
    return new WCButton();
  }
}
